import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path:'/',
    redirect:'/login'
  },
  {
    path:'/login',
    component:Login
  },

  {
    path:'/home',
    component: () => import('../components/Home.vue'),
    redirect:'/welcome',
    children:[
      { path:'/welcome', meta: {title: '欢迎页'}, component:() => import('../components/index/Welcome.vue') },
      { path:'/movies',meta: {title: '电影管理 / 电影列表'},component:() => import('../components/movie/Movies.vue') },
      { path:'/movie/channel',meta: {title: '电影管理 / 渠道电影'},component:() => import('../components/movie/movie.channel.list.vue') },
      { path:'/sms',meta: {title: '短信查询 / 短信列表'},component:() => import('../components/sms/Sms.vue') },
      { path:'/cinemas',meta: {title: '影院管理 / 影院列表'}, component:() => import('../components/movie/Cinemas.vue') },
      { path:'/cinema/line/list',meta: {title: '影院管理 / 影院列表'}, component:() => import('../components/movie/cinema.gpline.vue') },
      { path:'/cinema/open/rule/list',meta: {title: '影院管理 / 影院开放规则'}, component:() => import('../components/movie/cinema.open.rule.vue') },
      { path:'/cinema/line/hall/list',meta: {title: '影院管理 / 院线影厅列表'}, component:() => import('../components/movie/cinema.gpline.hall.vue') },
      { path:'/cinema/hall/list',meta: {title: '影院管理 / 影院影厅列表'}, component:() => import('../components/movie/cinema.hall.rate.vue') },
      { path:'/cinema/special/hall/list',meta: {title: '影院管理 / 特殊影厅管理'}, component:() => import('../components/movie/cinema.special.hall') },
      { path:'/cinema/bmh/list',meta: {title: '影院管理 / 爆米花管理'}, component:() => import('../components/movie/cinema.bmh.batch') },
      { path:'/cinema/bmh/coupon/list',meta: {title: '影院管理 / 爆米花券管理'}, component:() => import('../components/movie/cinema.bmh.coupon') },
      { path:'/nl/opi/list/response',meta: {title: '影院管理 / 排期接口返回'}, component:() => import('../components/sys/nl.opi.response') },
      { path:'/users',meta: {title: '用户管理 / 用户列表'}, component:() => import('../components/user/Users.vue') },
      { path:'/rights',meta: {title: '用户管理 / 权限列表'}, component:() => import('../components/power/Rights.vue') },
      { path:'/roles',meta: {title: '用户管理 / 角色列表'}, component:() => import('../components/power/Roles.vue') },
      { path:'/menu/list',meta: {title: '用户管理 / 权限列表'},component:() => import('../components/menu/Menus.vue') },
      { path:'/order/movie/list',meta: {title: '订单管理 / 电影订单列表'}, component:() => import('../components/order/movie.order.list.vue') },
      { path:'/order/list',meta: {title: '订单管理 / 订单列表'}, component:() => import('../components/order/mall.order.list.vue') },
      { path:'/order/detail',meta: {title: '订单管理 / 订单详情'}, component:() => import('../components/order/mall.order.detail') },
      { path:'/order/bmh/list',meta: {title: '订单管理 / 爆米花列表'}, component:() => import('../components/order/bmhorder.list') },
      { path:'/order/movie/jiedan/count',meta: {title: '订单管理 / 接单统计'}, component:() => import('../components/order/jiedan.count.vue') },
      { path:'/order/movie/order/count',meta: {title: '订单管理 / 订单统计'}, component:() => import('../components/order/order.count.vue') },
      { path:'/member/list',meta: {title: '会员管理 / 会员列表'}, component:() => import('../components/member/Members.vue') },
      { path:'/feedback/list',meta: {title: '会员管理 / 建议列表'}, component:() => import('../components/member/feed.back.vue') },
      { path:'/order/refund/apply',meta: {title: '退款管理 / 电影申请退款'}, component:() => import('../components/refund/refundApply.vue') },
      { path:'/order/refund/apply4MemberCharge',meta: {title: '退款管理 / 会员充值申请退款'}, component:() => import('../components/refund/refundApply4MemberCharge.vue') },
      { path:'/order/refund/apply4Bmh',meta: {title: '退款管理 / 爆米花申请退款'}, component:() => import('../components/refund/refundApply4Bmh') },
      { path:'/order/refund/list',meta: {title: '退款管理 / 退款列表'}, component:() => import('../components/refund/refundOrderList.vue') },
      { path:'/member/refund/apply/list',meta: {title: '退款管理 / 用户申请退款'}, component:() => import('../components/member/member.apply.refund') },
      { path:'/sys/cfg/list',meta: {title: '系统管理 / 系统配置'}, component:() => import('../components/sys/sys.cfg') },
      { path:'/sys/cfg/movieOrderNote',meta: {title: '系统管理 / 电影注意事项'}, component:() => import('../components/sys/order.note') },
      { path:'/sys/cfg/member/refund/apply/cfg',meta: {title: '系统管理 / 用户申请退款配置'}, component:() => import('../components/sys/member.refund.apply.cfg') },
      { path:'/sys/cfg/movie/lock/seat/switch',meta: {title: '系统管理 / 锁座开关'}, component:() => import('../components/sys/movie.lock.seat.switch') },
      { path:'/sys/sql/query',meta: {title: '系统管理 / Sql查询'}, component:() => import('../components/sys/sql') },
      { path:'/nl/cinema/list/response',meta: {title: '系统管理 / 南里影院返回'}, component:() => import('../components/sys/nl.cinema.response') },
      { path:'/sys/nl/balance',meta: {title: '系统配置 / 南里余额查询'}, component:() => import('../components/sys/nldyp.balance') },
      { path:'/coupon/batch/list',meta: {title: '卡券管理 / 批次列表'}, component:() => import('../components/coupon/coupon.batch.list.vue') },
      { path:'/coupon/list',meta: {title: '卡券管理 / 卡券列表'}, component:() => import('../components/coupon/coupon.list.vue')},
      { path:'/user/bind/coupon/list',meta: {title: '卡券管理 / 管理员绑券'}, component:() => import('../components/coupon/user.bind.coupon.list')},
      { path:'/movie/channel/sort/list',meta: {title: '电影管理 / 购票取票排序'}, component:() => import('../components/movie/movie.channel.sort')},
      { path:'/memberCharge/category/list',meta: {title: '视听会员充值 / 分类信息'}, component:() => import('../components/member_charge/category.list')},
      { path:'/memberCharge/subCategory/list',meta: {title: '视听会员充值 / 子分类信息'}, component:() => import('../components/member_charge/category.sub.list')},
      { path:'/memberCharge/subCategory/tp/list',meta: {title: '视听会员充值 / 子分类信息 / 规格'}, component:() => import('../components/member_charge/tp.list')},
      { path:'/memberCharge/sku/list',meta: {title: '视听会员充值 / Sku'}, component:() => import('../components/member_charge/sku.list')},
      { path:'/order/memberCharge/list',meta: {title: '订单管理 / 订单列表'}, component:() => import('../components/order/member.charge.order.list')},
      { path:'/member/account/charge/cfg',meta: {title: '账户余额/ 充值配置'}, component:() => import('../components/member/member.account.charge.cfg')},
      { path:'/member/account/trs/flow',meta: {title: '账户余额/ 交易流水'}, component:() => import('../components/member/member.account.trs.flow')},
      { path:'/mall/category/list',meta: {title: '商城基本配置/ 分类管理'}, component:() => import('../components/mall/Category')},
      { path:'/mall/vendor/list',meta: {title: '商城基本配置/ 供应商管理'}, component:() => import('../components/mall/Vendor')},
      { path:'/mall/shipper/list',meta: {title: '商城基本配置/ 发货商管理'}, component:() => import('../components/mall/Shipper')},
      { path:'/mall/shippingtemplate/list',meta: {title: '商城基本配置/ 快递模板管理'}, component:() => import('../components/mall/ShippingTemplate')},
      { path:'/mall/product/list',meta: {title: '商城商品/ 商品管理'}, component:() => import('../components/mall/Product')},
    ]
  }
]

const router = new VueRouter({
  mode: "history",
  routes
})

// 配置路由守卫
router.beforeEach( (to,from,next) => {
  window.document.title = to.meta.title == undefined?'Emall':to.meta.title
  // 如果访问登陆页，则放行
  if(to.path === '/login'){
    return next()
  }
  // 如果用户未登陆，则跳转到/login
  const userInfo = localStorage.getItem('uuid')
  if(!userInfo){
    return next('/login')
  }
  // 如果用户已登陆，则放行
  next()
})

export default router
